package com.wkq.move.module.main.ui.adapter;

import android.os.Build;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.wkq.move.R;
import com.wkq.net.model.USTVShowInfo;
import com.youth.banner.adapter.BannerAdapter;
import com.youth.banner.util.BannerUtils;

import java.util.List;

/**
 * 作者: 吴奎庆
 * <p>
 * 时间: 2020/5/23
 * <p>
 * 简介:
 */
public class MoveTopAdapter extends BannerAdapter<USTVShowInfo, ImageHolder> {

    public MoveTopAdapter(List<USTVShowInfo> mDatas) {
        super(mDatas);
    }

    @Override
    public ImageHolder onCreateHolder(ViewGroup parent, int viewType) {
        ImageView imageView = (ImageView) BannerUtils.getView(parent, R.layout.banner_image);
        //通过裁剪实现圆角
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            BannerUtils.setBannerRound(imageView, 20);
//        }
        return new ImageHolder(imageView);
    }

    @Override
    public void onBindView(ImageHolder holder, USTVShowInfo data, int position, int size) {
        //通过图片加载器实现圆角，你也可以自己使用圆角的imageview，实现圆角的方法很多，自己尝试哈
        RequestOptions requestOptions = RequestOptions.placeholderOf(R.mipmap.bg_pro_comment).error(R.mipmap.bg_pro_comment)
                .centerCrop().diskCacheStrategy(DiskCacheStrategy.RESOURCE).dontAnimate();

        Glide.with(holder.itemView)
                .load(data.getTvPoster())
                .apply(requestOptions)
                .into(holder.imageView);
    }

}
